using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using NHibernate.Criterion;

using QLTDK.Entities;
using QLTDK.DataAccess.BaseDaos;
using QLTDK.DataAccess.Interfaces;

namespace QLTDK.DataAccess
{
	public class TdkTudieukhienDao : BaseTdkTudieukhienDao, ITdkTudieukhienDao
    {
        public Boolean IsExist(TdkTudieukhien tdk)
        {
            IList<TdkTudieukhien> lstTDK = GetByTenTDKVaCongTrinhLapDat(tdk.TenTDK, tdk.MaCongTrinhLapDat);

            if (lstTDK.Count > 0)
                return true;
            return false;
        }

        public IList<TdkTudieukhien> GetByTenTDK(System.String tenTDK)
        {
            return HibernateTemplate.ExecuteFind<TdkTudieukhien>(

                delegate(ISession session)
                {
                    ICriteria criteria = session.CreateCriteria(typeof(TdkTudieukhien));

                    criteria.Add(Expression.Eq("TenTDK", tenTDK));

                    return criteria.List<TdkTudieukhien>();
                });
        }

        public IList<TdkTudieukhien> GetByTenTDKVaCongTrinhLapDat(String tenTDK, CtrCongtrinh congTrinhLapDat)
        {
            return HibernateTemplate.ExecuteFind<TdkTudieukhien>(

                delegate(ISession session)
                {
                    ICriteria criteria = session.CreateCriteria(typeof(TdkTudieukhien));
                    
                    criteria.Add(Expression.Eq("TenTDK", tenTDK));
                    criteria.Add(Expression.Eq("MaCongTrinhLapDat.Id", congTrinhLapDat.Id));

                    return criteria.List<TdkTudieukhien>();
                });
        }
	}
}